package com.example.photography.adapter.message;

import android.content.Context;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.photography.R;
import com.example.photography.adapter.MyBaseAdapter;
import com.example.photography.bean.MessagesBean;
import com.example.photography.ui.CircleImageView;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MessageAdapter extends MyBaseAdapter {
    public MessageAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public View myGetView(int position, View convertView) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_like_and_save, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        MessagesBean messagesBean = (MessagesBean) list.get(position);
        Glide.with(mContext)
                .load(messagesBean.getHead_url())
                .thumbnail(Glide.with(mContext).load(R.drawable.loading))
                .into(viewHolder.ivHead);
        viewHolder.tvName.setText(messagesBean.getName());
        viewHolder.tvContent.setText(messagesBean.getContent());
        viewHolder.tvDate.setText(messagesBean.getDate());
        viewHolder.svCover.setImageURI(messagesBean.getCover());

        return convertView;
    }

    static
    class ViewHolder {
        @BindView(R.id.iv_head)
        CircleImageView ivHead;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_content)
        TextView tvContent;
        @BindView(R.id.tv_date)
        TextView tvDate;
        @BindView(R.id.sv_cover)
        SimpleDraweeView svCover;
        @BindView(R.id.rl_item)
        RelativeLayout rlItem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
